import json

from moralis import evm_api

def get_ethScan_data(tx_hash):
    # url = "https://eth-mainnet.g.alchemy.com/v2/qP2MhWkxOaIXq7Z2Ijab1DG8AIu3pBVO"

    # payload = {
    #     "id": 1,
    #     "jsonrpc": "2.0",
    #     "method": "eth_getTransactionByHash",
    #     "params": [f"0x{txhash}"]
    # }
    # headers = {
    #     "accept": "application/json",
    #     "content-type": "application/json",
    #     'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0'
    # }
    #
    # response = requests.post(url, json=payload, headers=headers)
    #
    #
    # if response.status_code == 200:
    #     print("ETH链数据爬取完成！")
    #     return response.json()
    # else:
    #     print(f"Error: {response.status_code}, {response.text}")
    api_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJub25jZSI6IjRlYTNjMzQ2LThjNTctNGNhMC05MTZjLTJlMDFlZGE3NTVkMyIsIm9yZ0lkIjoiMzc0NDYyIiwidXNlcklkIjoiMzg0ODIyIiwidHlwZUlkIjoiNDQ3MTNkYWItYmJmNy00Nzg0LThkOWUtZjZhNWEyNmYyN2FhIiwidHlwZSI6IlBST0pFQ1QiLCJpYXQiOjE3MDYzNjA1MjUsImV4cCI6NDg2MjEyMDUyNX0.2ETgC13ITXtx6jZmb6k6hoZgt25-QnDSWNSs5ALWgUM"
    Params = {
        "chain": "eth",
        "transaction_hash": f"0x{tx_hash}"
    }
    result = evm_api.transaction.get_transaction(
        api_key=api_key,
        params=Params
    )
    print("ETH链数据爬取完成！")
    # json_data = json.dumps(result, indent=4)
    # with open('../../data_new/ethdata.json', 'w', encoding='utf-8') as f:
    #     f.write(json_data)
    return result
# get_ethScan_data("cf205cf4625d5a065cb2cd806e23e6d9b0235890e4934a7ee665c9484a5a2a56")


